﻿<?php 
class ControllerPageManage extends Controller{

	public function index(){
		
		$this->isLogin();
		
		$this->getList();
	}

	public function getList(){
	
		$this->load->model("page/common");
	
		$this->data["logout"]=$this->url->link("page/logout");
		$this->data["all"]=$this->url->link("page/manage");
		$this->data["filter_ip"]=$this->url->link("page/manage")."&ip=";
		
		if (isset($this->request->get['ip'])) {
			$ip = $this->request->get['ip'];
		} 
		
		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}
		
		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}
		
		$limit=18;
		
		$data = array(
			'start'           => ($page - 1) * $limit,
			'limit'           => $limit
		);
		
		if(isset($ip)){
			$data["ip"]=$ip;
		}
		
		$visit_total=$this->model_page_common->getTotalVisits($data);
		$visits=$this->model_page_common->getVisits($data);
		
		$this->data["visits"]=$visits;
		$this->data["visit_total"]=$visit_total;
		
		$pagination = new Pagination();
		$pagination->total = $visit_total;
		$pagination->page = $page;
		$pagination->limit = $limit;
		$pagination->text = "pagenation";
		$pagination->url = $this->url->link('page/manage',  $url . '&page={page}');
			
		$this->data['pagination'] = $pagination->render();
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/page/manage.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/page/manage.tpl';
		} else {
			$this->template = 'default/template/page/manage.tpl';
		}
										
		$this->response->setOutput($this->render());
	}
}
?>